class Zcsh.java {
    public int findTargetSumWays(int[] nums, int S) {
        int[][] result = new int[nums.length][2001];
        result[0][nums[0] + 1000] = 1;
        result[0][-nums[0] + 1000] += 1;
        for (int i = 1; i < nums.length; i++) {
            for (int sum = 0; sum <= 2000; sum++) {
                if (result[i - 1][sum] > 0) {
                    result[i][sum + nums[i]] += result[i - 1][sum];
                    result[i][sum - nums[i]] += result[i - 1][sum];
                }
            }
        }
        return S > 1000 ? 0 : result[nums.length - 1][S + 1000];
    }
}